<cfcomponent displayname="snip gateway" hint="">

	<cffunction name="init" access="public" returntype="snipGateway" output="false" displayname="snip Constructor" hint="I initialize a snip.">
		<cfargument name="datasourceSettings" type="any" required="true" />
		
		<cfset variables.dsn = arguments.datasourceSettings.getConfigSetting("dsn") />
		<cfset variables.dbtype = arguments.datasourceSettings.getConfigSetting("dbtype") />

		<cfreturn this />
	</cffunction>

	<cffunction name="getAll" access="public" returntype="query" output="false" displayname="" hint="">

		<cfset var snipSelect = 0 />
		<cfquery name="snipSelect" datasource="#variables.dsn#">
			SELECT * 
			FROM	snip	
		</cfquery>

		<cfreturn snipSelect/>
	</cffunction>
	 
	<cffunction name="getSnipsByLibID" access="public" returntype="query" output="false" displayname="" hint="">
		<cfargument name="libID" type="numeric">
		<cfargument name="userID" type="string">
		
		<cfset var snipSelect = 0 />
		<cfquery name="snipSelect" datasource="#variables.dsn#">
			SELECT 	t2.snipid, t2.name as snipName, t2.useremail, t2.help, t2.description as snipDescription, t2.starttext, t2.endtext, 
					t2.author, t2.platforms, t2.template, t2.created as snipCreateDT, t2.updated as snipUpdateDT, 
					t2.published, t2.ownerid as snipOwner, t1.name as libName, t1.description as libDescription, 
					t1.parent as parentLibID, t1.created as libCreateDT, t1.updated as libUpdateDT, t1.isPublic, 
					t1.ownerID as libOwnerID, t1.libID
			FROM	snip t2 LEFT JOIN
					lib t1 ON t1.libid = t2.parent
					<cfif arguments.libid gt 0>
					AND t1.libID = <cfqueryparam cfsqltype="cf_sql_varchar" value="#arguments.libID#">
					</cfif>
			WHERE	libid IN   (SELECT 	libiD
							  	FROM 	libAccess 
							 	WHERE	userID = <cfqueryparam cfsqltype="cf_sql_varchar" value="#arguments.userID#">
								)
			ORDER BY t1.libID, t2.snipID
					
		</cfquery> 

		<cfreturn snipSelect/>
	</cffunction>
	
</cfcomponent>